<?php

class AppController extends UserController
{
	public function init()
	{
		parent::init();
		$this->userleftsign = 'app';
	}

	public function indexAction()
	{
		$this->title = '我的应用';
		$page=I('get.page','int',1);
		$pagesize=10;
		$this->list=M('app')->where(array('user_id'=>$this->userinfo['id'],'status'=>1))->page($page)->limit($pagesize)->order('id desc')->getlist();
		$this->pagestr=page::show(M('app')->where(array('user_id'=>$this->userinfo['id']))->count(),$pagesize,$page);
		$this->display();
	}

	public function addAction()
	{
		$this->title='添加应用';
		if (IS_POST){
			$app=M('app')->getapplist();
			$param['app']=I('post.app','en','我的应用');
			$param['version']=I('post.version','int',0);
			$param['service']=I('post.service','int',0);
			$param['name']=I('post.name','cn','');
			$param['intro']=safetext(I('post.intro','str',''));
			if ($app[$param['app']]['version'][$param['version']]['needvip']>0 && $this->userinfo['vipgroup']==''){
				//todo VIP链接
				$this->error('该应用限制VIP才能创建，请您先成为VIP！');
			}
			if ($orderid=M('app')->create($param)){
				$this->success('添加应用成功，请您进行付款',U('user.order.detail',array('orderid'=>$orderid)));
			}else{
				$this->error('添加失败，请联系管理员','',0);
			}
		}
		$this->app=json_encode(M('app')->getapplist(),256);
		$this->display();
	}

	public function detailAction()
	{
		$appid=I('get.appid','str','');
		$this->info=M('app')->getinfo($appid);
		$this->title='应用信息';
		$this->display();
	}

	public function manageAction()
	{
		$appid=I('get.appid','str','');
		$this->info=M('app')->getinfo($appid);
        if ($this->info['status']==0){
            $this->error('该应用尚未完成支付',U('user.order.detail',array('orderid'=>$this->info['order_id'])));
        }
		$this->title='应用管理';
		$this->display();
	}

	public function upgradeAction(){
		$appid=I('get.appid','str','');
		$this->info=M('app')->getinfo($appid);
		$this->title='应用升级续费';
		$this->display();
	}

}